export * from "./cesium";

/**
 * API 配置
 */
export const API_CONFIG = {
  // 基础 API 地址 - 根据环境自动选择
  BASE_URL:
    import.meta.env.VITE_API_BASE_URL ||
    (import.meta.env.DEV
      ? "/api" // 开发环境使用代理路径
      : "/api"), // 生产环境也使用 /api 路径

  // 录像查询服务器配置 - 支持动态获取
  PLAYBACK_SERVER: {
    // 默认配置，会被动态获取的值覆盖
    HOST: import.meta.env.VITE_PLAYBACK_HOST || "127.0.0.1",
    PORT: import.meta.env.VITE_PLAYBACK_PORT || "25080",
    PROTOCOL: import.meta.env.VITE_PLAYBACK_PROTOCOL || "http",
  },

  // API 路径配置
  ENDPOINTS: {
    // 认证相关
    AUTH: {
      LOGIN: "/auth/login",
      LOGOUT: "/auth/logout",
      REFRESH: "/auth/refreshToken",
      USER_INFO: "/auth/user",
      CHANGE_PASSWORD: "/auth/password",
    },

        // 菜单管理
    MENU: {
      LIST: "/menus",
      TREE: "/menus/tree",
      DETAIL: (id: number) => `/menus/${id}`,
      CREATE: "/menus",
      UPDATE: (id: number) => `/menus/${id}`,
      DELETE: (id: number) => `/menus/${id}`,
    },
    
    // 设备目录
    Device_Menu: {
      ALL_MENU: "/menuController/getAllMenu",
      ALL_MENU_COUNT: "/menuController/getAllMenuWithDevCnt",
    },

    // 设备管理
    DEVICE: {
        // 根据菜单ID获取设备列表
      ListByMenuID: (id: string,isGetALL:boolean = false) => `/deviceController/getDeviceListByMenu?menuId=${id}&isGetALL=${isGetALL}`,
      // 地图设备
      ALL_DEVICE_IN_MAP: "/deviceController/getAllDeviceListInMap",
      STREAM: {
        LIST: "/devices/streams",
        DETAIL: (id: number) => `/devices/streams/${id}`,
        CREATE: "/devices/streams",
        UPDATE: (id: number) => `/devices/streams/${id}`,
        DELETE: (id: number) => `/devices/streams/${id}`,
      },
      NMC: {
        LIST: "/devices/nmc",
        DETAIL: (id: number) => `/devices/nmc/${id}`,
        CREATE: "/devices/nmc",
        UPDATE: (id: number) => `/devices/nmc/${id}`,
        DELETE: (id: number) => `/devices/nmc/${id}`,
      },
    },
    // 摄像头相关
    CAMERA: {
      LIST: "/cameras",
      DETAIL: (id: number) => `/cameras/${id}`,
      STATUS: (id: number) => `/cameras/${id}/status`,
      RECORDS: (id: number) => `/cameras/${id}/records`,
      START_RECORD: (id: number) => `/cameras/${id}/record/start`,
      STOP_RECORD: (id: number) => `/cameras/${id}/record/stop`,
      VIDEO_URL: (id: number, type: string) => `/cameras/${id}/video/${type}`,
      PTZ_CONTROL: (id: number) => `/cameras/${id}/ptz`,
      PRESETS: (id: number) => `/cameras/${id}/presets`,
      GOTO_PRESET: (id: number, presetId: number) =>
        `/cameras/${id}/presets/${presetId}/goto`,
    },

    // 用户管理
    USER: {
      LIST: "/users",
      DETAIL: (id: number) => `/users/${id}`,
      CREATE: "/users",
      UPDATE: (id: number) => `/users/${id}`,
      DELETE: (id: number) => `/users/${id}`,
    },





    // 报警系统
    ALARM: {
      LIST: "/alarmInfo/getAlarmInfoListByPage",
      EXPORT: "/alarmInfo/exportInfos",
      DETAIL: (id: number) => `/alarms/${id}`,
      HANDLE: (id: number) => `/alarms/${id}/handle`,
      STATISTICS: "/alarms/statistics",
    },

    // 录像查询系统 - 使用特定的IP和端口
    PLAYBACK: {
      QUERY_VOD: "/nvrserver/v1/record/query_vod",
      PLAYBACK_STREAM_ID: "/nvrserver/v1/record/playback_stream_id",
    },
  },

  // 请求配置
  REQUEST_CONFIG: {
    TIMEOUT: 60000,
    RETRY_COUNT: 3,
    RETRY_DELAY: 1000,
  },
};

/**
 * 获取完整的 API URL
 */
export function getApiUrl(endpoint: string): string {
  return `${API_CONFIG.BASE_URL}${endpoint}`;
}

/**
 * 获取录像查询服务器的完整 URL
 */
export function getPlaybackServerUrl(endpoint: string): string {
  const { PROTOCOL, HOST, PORT } = API_CONFIG.PLAYBACK_SERVER;
  return `${PROTOCOL}://${HOST}:${PORT}${endpoint}`;
}

/**
 * API 状态码常量
 */
export const HTTP_STATUS = {
  OK: 200,
  CREATED: 201,
  NO_CONTENT: 204,
  BAD_REQUEST: 400,
  UNAUTHORIZED: 401,
  FORBIDDEN: 403,
  NOT_FOUND: 404,
  INTERNAL_SERVER_ERROR: 500,
} as const;

/**
 * 业务状态码常量
 */
export const BUSINESS_CODE = {
  SUCCESS: 200,
  FAIL: 500,
  UNAUTHORIZED: 401,
  FORBIDDEN: 403,
  NOT_FOUND: 404,
  VALIDATION_ERROR: 422,
} as const;
